<?php
namespace waf\client\monitor;

use \waf\Waf;
use \waf\log\WLog;
use \waf\modules\WCFunc;
use \waf\client\rpc\WRpcClient;

class WReportClient
{
    /**
     * 上报统计数据
     * @param string $module
     * @param string $interface
     * @param bool $success
     */
    public static function reportServerStatus($intMasterPid = 0, $status = 0)
    {
        $server_name    = Waf::getConfig('server', 'name');
        $server_ip      = Waf::getConfig('server', 'ip');
        $server_port    = Waf::getConfig('server', 'port');
        $start_time     = date('Y-m-d H:i:s', time());
        $work_nums      = Waf::getConfig('server', 'setting')['worker_num'];

        WLog::logDebug("in. master_pid = $intMasterPid, server_name = $server_name, server_ip = $server_ip, server_port = $server_port, start_time = $start_time, work_nums = $work_nums, status = $status", __FILE__, __LINE__, __FUNCTION__);

        $arrParams = array(
            'url'           =>  '/report/serverStatus',
            'server_name'   =>  $server_name,
            'server_ip'     =>  $server_ip,
            'server_port'   =>  $server_port,
            'start_time'    =>  $start_time,
            'work_nums'     =>  $work_nums,
            'status'        =>  $status,
            'master_pid'    =>  $intMasterPid,
        );

        $conf   = Waf::getConfig('rpc_server', 'monitor_server');
        WLog::logDebug("conf = ".WLog::toJson($conf), __FILE__, __LINE__, __FUNCTION__);

        WRpcClient::sendNormalUdpData($conf, $arrParams);
    }

}
?>
